package com.hnue.k60b.utils;

import java.net.URL;
import java.util.List;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import com.hnue.k60b.models.RssItem;
//truyen vao link, su dung rsshandle de lay ra du lieu
public class RssParser {
	public List<RssItem> getnewlist(String link){
		try{
		//truyen vao link
		URL url = new URL(link);
		
		SAXParserFactory factory = SAXParserFactory.newInstance();
		SAXParser parser = factory.newSAXParser();
		XMLReader reader = parser.getXMLReader();
		RssHandle handel = new RssHandle();
		reader.setContentHandler(handel);
		InputSource sourse = new InputSource(url.openStream());
		reader.parse(sourse); 
		return handel.getItemlist();
		}
		catch (Exception e) {
			e.printStackTrace();
			return null; 
		}
		
	}
}
